#!/bin/bash

echo "安装python2.7"

echo "更新apt"
apt update

echo "安装依赖"
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev curl libbz2-dev

if [ ! -f Python-2.7.18.tar.xz ]; then
    echo "本地不存在Python-2.7.18.tar.xz"
    curl -O https://mirrors.huaweicloud.com/python/2.7.18/Python-2.7.18.tar.xz
fi

echo "解压python2.7"
tar -xf Python-2.7.18.tar.xz

echo "配置python2.7"
cd Python-2.7.18
./configure --enable-optimizations

echo "编译python2.7"
make -j $(nproc)

echo "安装python2.7"
make altinstall

echo "复制python2.7到/usr/bin"
cp /usr/local/bin/python2.7 /usr/bin/python2.7
cp /usr/local/bin/python2.7 /usr/bin/python2

echo "验证python2.7"
python2 --version

echo "清理python2.7残留文件"
cd ..
rm -rf Python-2.7.18 Python-2.7.18.tar.xz
